package 笔试;

import java.util.Scanner;
import java.util.Stack;

/**
 * @Date 2024/11/10 15:26
 * @description: 拼多多笔试
 * .
 * @Author LittleNight
 */
public class pinduoduo {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            String[] str = new String[n];
            for(int i = 0; i < n; i++) {
                str[i] = in.next();
            }
            for (int i = 0; i < n; i++) {

                System.out.println(maxCount(str[i]));
            }
        }
    }

    private static int maxCount(String s) {
        char[] ch = s.toCharArray();
        int n = s.length();
        // 判断字符中有多少连续的 p d d字符
        int p = 0, d = 0, dd = 0;
        for (int i = 0; i < n; i++) {
            if (ch[i] == 'p' || ch[i] == 'P') p++;
            else if (ch[i] == 'd' || ch[i] == 'D') d++;
        }
        int tmp = d / 2;
        if (tmp <= p) return tmp;
        else return p;

        // 利用栈
//        int ans = 0;
//        int count = 0;
//        Stack<Character> stack = new Stack<>();
//        for (int i = 0; i < ch.length; i++) {
//            if(ch[i] == 'd' || ch[i] == 'D') count++;
//            stack.push(ch[i]);
//            if((ch[i] == 'd' || ch[i] == 'D') && count == 2) {
//                // 判断是不是pdd连续的
//            }
//        }

    }

}
